package shujia.day11;

public class Student2 implements Comparable<Student2> {
    private String name;
    private int chinese;
    private int math;
    private int english;

    public Student2() {
    }

    public Student2(String name, int chinese, int math, int english) {
        this.name = name;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEnglish() {
        return english;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    public int getSumScore() {
        return chinese + math + english;
    }

    @Override
    public String toString() {
        return "Student2{" +
                "name='" + name + '\'' +
                ", chinese=" + chinese +
                ", math=" + math +
                ", english=" + english +
                '}';
    }

    @Override
    public int compareTo(Student2 o) {
        //按照总分从高到低输出到控制台
        // this - 待插入的元素
        // o - 根的元素
        //显式条件
        int i1 = o.getSumScore() - this.getSumScore();
        // 隐藏条件
        // 总分一样，语文成绩不一定一样
        int i2 = (i1 == 0) ? o.getChinese() - this.getChinese() : i1;
        //总分一样，语文成绩一样，数学成绩不一定一样
        int i3 = (i2 == 0) ? o.getMath() - this.getMath() : i2;
        // 三门科目成绩都一样，姓名不一定一样
        return (i3 == 0) ? o.getName().compareTo(this.getName()) : i3;

    }
}
